for REStat paper, "Breastfeeding and Children's Early Cognitive Outcomes."


libname dd 'c:\local_c\bfeed3';
data x;
infile 'c:\local_c\bfeed3\extra08.dat' lrecl=174 missover DSD DLM=' ';
input
  C0000100
  C0000200
  C0005300
  C0005400
  C0005500
  C0005700
  C0356400
  C0357300
  C0358200
  C0591700
  C0591800
  C0591900
  C0592000
  C0811100
  C0811200
  C0811300
  C0811400
  C1001100
  C1001200
  C1001300
  C1001400
  C1204700
  C1204800
  C1204900
  C1205000
  C1524700
  C1524800
  C1524900
  C1525000
  C1771100
  C1771200
  C1771300
  C1771400
  C2244100
  C2244200
  C2244300
  C2244700
  C2687600
  C2687700
  C2687800
  C2688300
  C2969100
  C2969200
  C2969300
  C2969600
  C3549100
  C3549200
  C3549300
  C3549600
  C3893500
  C3893600
  C3893700
  C3894000
;


  label C0000100 = "ID CODE OF CHILD";
  label C0000200 = "ID CODE OF MOTHER OF CHILD";
  label C0005300 = "RACE OF CHILD (FROM MOTHERS SCREENER 79)";
  label C0005400 = "SEX OF CHILD";
  label C0005500 = "DATE OF BIRTH OF CHILD - MONTH";
  label C0005700 = "DATE OF BIRTH OF CHILD - YEAR";
  label C0356400 = "CHILD IN REG CHILD CARE DURING 1ST YR";
  label C0357300 = "CHILD IN REG CHILD CARE DURING 2ND YR";
  label C0358200 = "CHILD IN REG CHILD CARE DURING 3RD YR";
  label C0591700 = "CHILD IS CURRENTLY ATTENDING PRESCHOOL";
  label C0591800 = "CHILD EVER ENROLLED IN PRESCHOOL";
  label C0591900 = "CHILD EVER ENROLLED IN DAY CARE";
  label C0592000 = "CHILD EVER ENROLLED IN HEAD START";
  label C0811100 = "CHILD CURRENTLY ATTEND NURSERY/PRESCHOOL";
  label C0811200 = "CHILD CURRENTLY ENROLLED IN PRESCHOOL";
  label C0811300 = "CHILD EVER BEEN ENROLLED IN DAY CARE";
  label C0811400 = "CHILD EVER ENROLLED IN HEAD START PROGRM";
  label C1001100 = "CHILD CURR ATTEND NURSERY/PRESCHOOL?-92";
  label C1001200 = "CHILD EVER ENROLLED IN PRESCHOOL? 92";
  label C1001300 = "CHILD EVER BEEN ENROLLED IN DAY CARE?-92";
  label C1001400 = "CHILD EVER ENRLD IN HEAD START PROGRM-92";
  label C1204700 = "MACH CHK: CH CURR ATT NURSERY/PRESCH 94";
  label C1204800 = "CHILD EVER ENROLLED IN PRESCHOOL 94";
  label C1204900 = "CHILD EVER BEEN ENROLLED IN DAY CARE 94";
  label C1205000 = "CHILD EVER ENRLD IN HEAD START PROGRM 94";
  label C1524700 = "MACH CHK: CH CURR ATT NURSERY/PRESCH 96";
  label C1524800 = "CHILD EVER ENROLLED IN PRESCHOOL 96";
  label C1524900 = "CHILD EVER BEEN ENROLLED IN DAY CARE 96";
  label C1525000 = "CHILD EVER ENRLD IN HEAD START PROGRM 96";
  label C1771100 = "MACH CHK: CH CUR ATT NURSRY/PRESCH 1998";
  label C1771200 = "CHILD EVER ENROLLED IN PRESCHOOL 1998";
  label C1771300 = "CHILD EVER ENROLLED IN DAY CARE 1998";
  label C1771400 = "CHILD EVER ENROLLED IN HEAD START 1998";
  label C2244100 = "MACH CHK: CH CUR ATT NURSRY/PRESCH 2000";
  label C2244200 = "CHILD EVER ENROLLED IN PRESCHOOL 2000";
  label C2244300 = "CHILD EVER ENROLLED IN DAY CARE 2000";
  label C2244700 = "CHILD EVER ENROLLED IN HEAD START 2000";
  label C2687600 = "MACH CHK: CH CUR ATT NURSRY/PRESCH 2002";
  label C2687700 = "CHILD EVER ENROLLED IN PRESCHOOL 2002";
  label C2687800 = "CHILD EVER ENROLLED IN DAY CARE 2002";
  label C2688300 = "CHILD EVER ENROLLED IN HEAD START 2002";
  label C2969100 = "MACH CHK: CH CUR ATT NURSRY/PRESCH 2004";
  label C2969200 = "CHILD EVER ENROLLED IN PRESCHOOL 2004";
  label C2969300 = "CHILD EVER ENROLLED IN DAY CARE 2004";
  label C2969600 = "CHILD EVER ENROLLED IN HEAD START 2004";
  label C3549100 = "MACH CHK: CH CUR ATT NURSRY/PRESCH 2006";
  label C3549200 = "CHILD EVER ENROLLED IN PRESCHOOL 2006";
  label C3549300 = "CHILD EVER ENROLLED IN DAY CARE 2006";
  label C3549600 = "CHILD EVER ENROLLED IN HEAD START 2006";
  label C3893500 = "MACH CHK: CH CUR ATT NURSRY/PRESCH 2008";
  label C3893600 = "CHILD EVER ENROLLED IN PRESCHOOL 2008";
  label C3893700 = "CHILD EVER ENROLLED IN DAY CARE 2008";
  label C3894000 = "CHILD EVER ENROLLED IN HEAD START 2008";


  data y;
  set x;

**these are xround variables;
ccyr1 = .;
ccyr2 = .;
ccyr3 = .;
if c0356400 = 1 then ccyr1 = 1;
if c0356400 = 0 then ccyr1 = 0;

if c0357300 = 1 then ccyr2 = 1;
if c0357300 = 0 then ccyr2 = 0;

if c0358200 = 1 then ccyr3 = 1;
if c0358200 = 0 then ccyr3 = 0;


pre88 = .;
if c0591700 = 1 then pre88 = 1;
if c0591800 = 1 then pre88 = 1;
if c0591800 = 0 then pre88 = 0;

day88 = .;
if c0591900 = 1 then day88 = 1;
if c0591900 = 0 then day88 = 0;

hdst88 = .;
if c0592000 = 1 then hdst88 = 1;
if c0592000 = 0 then hdst88 = 0;

pre90 = .;
if c0811100 = 1 then pre90 = 1;
if c0811200 = 1 then pre90 = 1;
if c0811200 = 0 then pre90 = 0;

day90 = .;
if c0811300 = 1 then day90 = 1;
if c0811300 = 0 then day90 = 0;

hdst90 = .;
if c0811400 = 1 then hdst90 = 1;
if c0811400 = 0 then hdst90 = 0;

pre92 = .;
if c1001100 = 1 then pre92 = 1;
if c1001200 = 1 then pre92 = 1;
if c1001200 = 0 then pre92 = 0;

day92 = .;
if c1001300 = 1 then day92 = 1;
if c1001300 = 0 then day92 = 0;

hdst92 = .;
if c1001400 = 1 then hdst92 = 1;
if c1001400 = 0 then hdst92 = 0;

pre94 = .;
if c1204700 = 1 then pre94 = 1;
if c1204800 = 1 then pre94 = 1;
if c1204800 = 0 then pre94 = 0;

day94 = .;
if c1204900 = 1 then day94 = 1;
if c1204900 = 0 then day94 = 0;

hdst94 = .;
if c1205000 = 1 then hdst94 = 1;
if c1205000 = 0 then hdst94 = 0;

pre96 = .;
if c1524700 = 1 then pre96 = 1;
if c1524800 = 1 then pre96 = 1;
if c1524800 = 0 then pre96 = 0;

day96 = .;
if c1524900 = 1 then day96 = 1;
if c1524900 = 0 then day96 = 0;

hdst96 = .;
if c1525000 = 1 then hdst96 = 1;
if c1525000 = 0 then hdst96 = 0;

pre98 = .;
if c1771100 = 90 then pre98 = 1;
if c1771200 = 1 then pre98 = 1;
if c1771200 = 0 then pre98 = 0;

day98 = .;
if c1771300 = 1 then day98 = 1;
if c1771300 = 0 then day98 = 0;

hdst98 = .;
if c1771400 = 1 then hdst98 = 1;
if c1771400 = 0 then hdst98 = 0;

pre00 = .;
if c2244100 = 90 then pre00 = 1;
if c2244200 = 1 then pre00 = 1;
if c2244200 = 0 then pre00 = 0;

day00 = .;
if c2244300 = 1 then day00 = 1;
if c2244300 = 0 then day00 = 0;

hdst00 = .;
if c2244700 = 1 then hdst00 = 1;
if c2244700 = 0 then hdst00 = 0;

pre02 = .;
if c2687600 = 90 then pre02 = 1;
if c2687700 = 1 then pre02 = 1;
if c2687700 = 0 then pre02 = 0;

day02 = .;
if c2687800 = 1 then day02 = 1;
if c2687800 = 0 then day02 = 0;

hdst02 = .;
if c2688300 = 1 then hdst02 = 1;
if c2688300 = 0 then hdst02 = 0;

pre04 = .;
if c2969100 = 90 then pre04 = 1;
if c2969200 = 1 then pre04 = 1;
if c2969200 = 0 then pre04 = 0;

day04 = .;
if c2969300 = 1 then day04 = 1;
if c2969300 = 0 then day04 = 0;

hdst04 = .;
if c2969600 = 1 then hdst04 = 1;
if c2969600 = 0 then hdst04 = 0;

pre06 = .;
if c3549100 = 90 then pre06 = 1;
if c3549200 = 1 then pre06 = 1;
if c3549200 = 0 then pre06 = 0;

day06 = .;
if c3549300 = 1 then day06 = 1;
if c3549300 = 0 then day06 = 0;

hdst06 = .;
if c3549600 = 1 then hdst06 = 1;
if c3549600 = 0 then hdst06 = 0;

pre08 = .;
if c3893500 = 90 then pre08 = 1;
if c3893600 = 1 then pre08 = 1;
if c3893600 = 0 then pre08 = 0;

day08 = .;
if c3893700 = 1 then day08 = 1;
if c3893700 = 0 then day08 = 0;

hdst08 = .;
if c3894000 = 1 then hdst08 = 1;
if c3894000 = 0 then hdst08 = 0;

proc sort;  by c0000100;

**will use with child data;

data z;
set dd.child08;
keep r0000100 c0000100 c0000200 year56;

proc sort;  by c0000100;  run;

data z2;
merge y z;  by c0000100;

if c0000200 ne .;

if year56 ne .;

data dd.extra08;
set z2;
keep c0000100 
pre56 day56 hdst56;

pre56 = .;
day56 = .;
hdst56 = .;
*will use the interview after for '86;
if year56 = 1986 then do;
   pre56 = pre88;
   day56 = day88;
   hdst56 = hdst88;
end;
**interview of for rest, or one after if missing;
if year56 = 1988 then do;
   pre56 = pre88;
   day56 = day88;
   hdst56 = hdst88;
   if pre56 = .  then pre56 = pre90;
   if day56 = . then day56 = day90;
   if hdst56 = . then hdst56 = hdst90;
end;
**interview of for rest, or one after if missing;
if year56 = 1990 then do;
   pre56 = pre90;
   day56 = day90;
   hdst56 = hdst90;
   if pre56 = .  then pre56 = pre92;
   if day56 = . then day56 = day92;
   if hdst56 = . then hdst56 = hdst92;
end;

if year56 = 1992 then do;
   pre56 = pre92;
   day56 = day92;
   hdst56 = hdst92;
   if pre56 = .  then pre56 = pre94;
   if day56 = . then day56 = day94;
   if hdst56 = . then hdst56 = hdst94;
end;

if year56 = 1994 then do;
   pre56 = pre94;
   day56 = day94;
   hdst56 = hdst94;
   if pre56 = .  then pre56 = pre96;
   if day56 = . then day56 = day96;
   if hdst56 = . then hdst56 = hdst96;
end;

if year56 = 1996 then do;
   pre56 = pre96;
   day56 = day96;
   hdst56 = hdst96;
   if pre56 = .  then pre56 = pre98;
   if day56 = . then day56 = day98;
   if hdst56 = . then hdst56 = hdst98;
end;

if year56 = 1998 then do;
   pre56 = pre98;
   day56 = day98;
   hdst56 = hdst98;
   if pre56 = .  then pre56 = pre00;
   if day56 = . then day56 = day00;
   if hdst56 = . then hdst56 = hdst00;
end;

if year56 = 2000 then do;
   pre56 = pre00;
   day56 = day00;
   hdst56 = hdst00;
   if pre56 = .  then pre56 = pre02;
   if day56 = . then day56 = day02;
   if hdst56 = . then hdst56 = hdst02;
end;

if year56 = 2002 then do;
   pre56 = pre02;
   day56 = day02;
   hdst56 = hdst02;
   if pre56 = .  then pre56 = pre04;
   if day56 = . then day56 = day04;
   if hdst56 = . then hdst56 = hdst04;
end;

if year56 = 2004 then do;
   pre56 = pre04;
   day56 = day04;
   hdst56 = hdst04;
   if pre56 = .  then pre56 = pre06;
   if day56 = . then day56 = day06;
   if hdst56 = . then hdst56 = hdst06;
end;

if year56 = 2006 then do;
   pre56 = pre06;
   day56 = day06;
   hdst56 = hdst06;
   if pre56 = .  then pre56 = pre08;
   if day56 = . then day56 = day08;
   if hdst56 = . then hdst56 = hdst08;
end;

if year56 = 2008 then do;
   pre56 = pre08;
   day56 = day08;
   hdst56 = hdst08;
end;




proc means;
run;
